/*
Copyright (C) Ariff Ehsan, Abdul Hadi Fikri

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*  Author : Ariff Ehsan
 *           Abdul Hadi Fikri
 *  Date   : June 18, 2009
 */

/**
 *  The purpose of this header file is to define all the dependecies hardware
 *  configuration.
 *
 */


#ifndef __ATMEGA644P_HARDWARE_H__
#define __ATMEGA644P_HARDWARE_H__

#include <avr/interrupt.h>
#include <avr/io.h>

#include <ports/atmega644p/timer/atmega644p_timer0.h>


/* Bit operators using bit number
 */
#define SET_BIT(port, bit)		((port) |= _BV(bit))
#define CLR_BIT(port, bit)		((port) &= ~_BV(bit))
#define READ_BIT(port, bit)		(((port) & _BV(bit)) != 0)
#define FLIP_BIT(port, bit)		((port) ^= _BV(bit))


/* System clock pulse pin
 */
#define CLOCK_PULSE_PORT PORTD
#define CLOCK_PULSE_DIR  DDRD
#define CLOCK_PULSE_PIN  PD0


/* Critical section management
 */
#define ENTER_CRITICAL()		asm volatile ( "in		__tmp_reg__, __SREG__" :: );	\
								asm volatile ( "cli" :: );								\
								asm volatile ( "push	__tmp_reg__" :: )

#define EXIT_CRITICAL()			asm volatile ( "pop		__tmp_reg__" :: );				\
								asm volatile ( "out		__SREG__, __tmp_reg__" :: )

#define DISABLE_INTERRUPTS()	asm volatile ( "cli" :: );
#define ENABLE_INTERRUPTS()		asm volatile ( "sei" :: );


#endif
